// ----------------------------------
// RSDK Project: Sonic 1/Sonic 2
// Script Description: Y Bound Adjust Object
// Script Author: Christian Whitehead/Simon Thomley
// Unpacked by Rubberduckycooly's script unpacker
// ----------------------------------

// Aliases
private alias 32 : TYPE_YBOUNDADJUST


// Static Values

// Tables

event ObjectMain
	if object.propertyValue == 0
		temp0 = object[0].xpos
		temp0 -= object.xpos
		Abs(temp0)
		if temp0 < 0x200000
			stage.newYBoundary1 = 0
			stage.newYBoundary2 = object.iypos
			stage.deathBoundary = object.ypos
		end if
	else
		if object[0].ypos < object.ypos
			if object[0].ypos > object[+1].ypos
				temp0 = object[0].xpos
				temp0 -= object.xpos
				Abs(temp0)
				if temp0 < 0x200000
					stage.newYBoundary2 = object.iypos
					stage.deathBoundary = object.ypos
					if object.value0 > 0
						stage.newXBoundary1 = object.value0
						object.value0 = 0
					end if
				end if
			end if
		end if
	end if
end event


event ObjectStartup
	foreach (TypeName[Y Bound Adjust], arrayPos0, ALL_ENTITIES)
		if options.vsMode == 0
			if object[arrayPos0].propertyValue == 0
				object[arrayPos0].priority = PRIORITY_XBOUNDS
				temp0 = object[0].xpos
				temp0 -= object[arrayPos0].xpos
				Abs(temp0)
				if temp0 < 0x200000
					stage.curYBoundary2 = object[arrayPos0].iypos
					stage.deathBoundary = object[arrayPos0].ypos
				end if
			else
				object[arrayPos0].priority = PRIORITY_XBOUNDS
				arrayPos1 = arrayPos0
				arrayPos1++
				if object[0].ypos < object[arrayPos0].ypos
					if object[0].ypos > object[arrayPos1].ypos
						temp0 = object[0].xpos
						temp0 -= object[arrayPos0].xpos
						Abs(temp0)
						if temp0 < 0x200000
							stage.curYBoundary2 = object[arrayPos0].iypos
							stage.deathBoundary = object[arrayPos0].ypos
						end if
					end if
				end if
			end if
		else
			object[arrayPos0].type = TypeName[Blank Object]
		end if
	next
end event

event RSDKDraw
	DrawSprite(0)
end event

event RSDKLoad
	LoadSpriteSheet("Global/Display.gif")
	SpriteFrame(-16, -16, 32, 32, 1, 143)
end event
